//
//  HJJSettingViewController.m
//  Pianke
//
//  Created by 黄俊杰 on 15/12/22.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "HJJSettingViewController.h"
#import "LDJ_settingHeaderView.h"
#import "LDJ_AboutViewController.h"
#import "HJJCollectViewController.h"

@interface HJJSettingViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic,retain)UITableView *tableView;
//@property (nonatomic,retain)UIImageView *headView;
@property (nonatomic,retain)LDJ_settingHeaderView *headerView;

@end

@implementation HJJSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:self.tableView];
    self.headerView = [[LDJ_settingHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200 * EACH_HEIGHT)];
    self.tableView.tableHeaderView = self.headerView;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self.headerView updateHeaderView:scrollView.contentOffset];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *filePath = @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:filePath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    if (indexPath.row == 0) {
        
        cell.textLabel.text = @"我的收藏";
        
    }
    else if (indexPath.row == 1){
    
        cell.textLabel.text = @"清理缓存";
    }
    else{
    
        cell.textLabel.text = @"关于PianKe";
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 60 * EACH_HEIGHT;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        HJJCollectViewController *collectVC = [[HJJCollectViewController alloc] init];
        [self.navigationController pushViewController:collectVC animated:1];
    }
    else if (indexPath.row == 1){
    
        NSInteger size = [[SDImageCache sharedImageCache] getSize];
        float totalSize = size / 1024.0 / 1024.0;
        
        
        UIAlertController *alert= [UIAlertController alertControllerWithTitle:@"温馨提示" message:[NSString stringWithFormat:@"共缓存了 %.2f M,确定清除么?",totalSize] preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *actionY = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[SDImageCache sharedImageCache] clearDisk];
            
        }];
        
        UIAlertAction *actionN = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {  
            
        }];
        
        [alert addAction:actionY];
        [alert addAction:actionN];
        
        [self presentViewController:alert animated:YES completion:^{
        }];
    }else if (indexPath.row == 2){
    
    
        LDJ_AboutViewController *aboutVC = [[LDJ_AboutViewController alloc] init];
        [self presentViewController:aboutVC animated:YES completion:^{
            
            
            
        }];
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
